﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;

namespace WpfPanel
{
    public class BlockWindow
    {
        public int Width { get { return 375; } }

        public int Height { get { return 270; } }

        public string DisplayName
        {
            get { return "BlockWindow"; }
        }

        public string DisplayNameIcon
        {
            get { return DisplayName + "Icon"; }
        }

        public string ResourceLocate 
        {
            get { return "/WpfPanel;component/BlockWindow.xaml"; }
        }

        public ResourceDictionary ResourceDict 
        { 
            get;
            private set; 
        }

        public ControlTemplate ControlTemplate { get; private set; }

        public ControlTemplate ControlTemplateIcon { get; private set; }

        public void LoadResource()
        {
            var res = new Uri(ResourceLocate, UriKind.Relative);
            ResourceDict = new ResourceDictionary() { Source = res };

            Application.Current.Resources.MergedDictionaries.Add(ResourceDict);
            var control = Application.Current.FindResource(DisplayName);
            var controlIcon = Application.Current.FindResource(DisplayNameIcon);

            if (control != null && control is ControlTemplate)
            {
                ControlTemplate = (ControlTemplate)control;
            }
            else
            {
                throw new Exception("Control is not loaded!");
            }

            if (controlIcon != null && controlIcon is ControlTemplate)
            {
                ControlTemplateIcon = (ControlTemplate)controlIcon;
            }
            else
            {
                throw new Exception("Control is not loaded!");
            }
        }

    }
}
